<template>
  <div class="details-container app-container" v-loading="listLoading">
    <div class="detail-title">
      <div>用户基础信息</div>
      <el-button type="primary" size="small" @click="changeUserInfo"
        >修改</el-button
      >
    </div>
    <div class="detail-content">
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">用户名称:</div>
          <div><el-input v-model="userDetail.nick_name" /></div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">用户ID:</div>
          <div>{{ userDetail.id_public_user_info }}</div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
        <el-col :span="12">
          <div class="left-text">用户类型:</div>
          <div>
            <el-radio-group v-model="userDetail.user_type">
              <el-radio :label="0">普通用户</el-radio>
              <el-radio :label="111">管理员</el-radio>
            </el-radio-group>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">性别:</div>
          <div>
            {{
              userDetail.user_sex === 1
                ? "男"
                : userDetail.user_sex === 2
                ? "女"
                : "不详"
            }}
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="80">
         <el-col :span="12">
          <div class="left-text">手机号:</div>
          <div>{{userDetail.user_phone}}</div>
        </el-col>
        <el-col :span="12">
          <div class="left-text">注册时间:</div>
          <div>{{ userDetail.time_register }}</div>
        </el-col>
      </el-row>

    </div>
    <div class="other-content">
      <div class="item-content">
        <div>
          <div>账户余额</div>
          <div class="number-text">{{ userAmountInfo.mid_table_remark_008|showUserAmount }}元</div>
        </div>
        <div><el-button @click="handleToRecharge">余额充值</el-button></div>
      </div>
    </div>
    <comp-recharge ref="refCompRecharge" @refreshAmount="getUserAmountInfo"></comp-recharge>
  </div>
</template>
<script>
import waves from "@/directive/waves"; // waves directive
import { orderList } from "@/api/order";
import {userAmountInfo} from "@/api/user"
import CompRecharge from "./components/recharge.vue"
export default {
  name: "UserDetails",
  directives: { waves },
  components:{
    CompRecharge,
  },
  data() {
    return {
      id_public_user_info:"",
      listLoading: true,
      userDetail: {},
      password: "",
      detailQuery: {
        invoke_method: "public_page_4m_load_user_list",
        id_public_user_info: null,
      },
      changeQuery: {
        invoke_method: "change_user_info",
        nick_name: null,
        user_type: null,
        pre_db_para_id_public_user_info: null,
      },
      userAmountInfo:{}
    };
  },
  filters:{
    showUserAmount(val){
      if(!val){
        return parseFloat("0").toFixed(2);
      }
      return parseFloat(val).toFixed(2)
    }
  },
  mounted() {
    let id = this.$route.query.id;
    this.id_public_user_info = id;
    this.detailQuery.id_public_user_info = id;
    this.changeQuery.pre_db_para_id_public_user_info = id;
    this.getList();
    this.getUserAmountInfo();
  },
  methods: {
    /*
     * 获取页面数据
     * */
    getList() {
      this.listLoading = true;
      orderList(this.Qs.stringify(this.detailQuery)).then((response) => {
        console.log(response);
        let tmpUserDetail = response.page_content||[];
        this.userDetail=tmpUserDetail[0]||{};
        this.otherInfo = response;

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false;
        }, 0.5 * 1000);
      });

    },
    async getUserAmountInfo(){
      let userInfoResult=await userAmountInfo(this.Qs.stringify({
        invoke_method:'static_4_money',
        pre_cmd_para_id_public_user_info:this.id_public_user_info,
        pre_cmd_para_type_list:1211
      })).catch(err=>{
        console.log(err,">>>>>>>>>")
      })
      console.log(userInfoResult,"userInfoResult>>>>>>>>>>>>>")
      if(userInfoResult){
        let big_data=userInfoResult.big_data||[];
        let amount=big_data[0]||{}
        this.userAmountInfo=amount;
      }
      else{
        this.userAmountInfo={};
      }
    },
    /*
     * 修改用户信息
     * */
    changeUserInfo() {
      this.changeQuery.nick_name = this.userDetail.nick_name;
      this.changeQuery.id_public_user_info = this.id_public_user_info;
      this.changeQuery.user_type = this.userDetail.user_type;
      orderList(this.Qs.stringify(this.changeQuery)).then((res) => {
        this.$notify({
          title: "Success",
          message: "修改成功",
          type: "success",
          duration: 2000,
        });
        this.getList();
      });
    },
    handleToRecharge(){
    this.$refs.refCompRecharge.onShowRecharge({
      id_public_user_info:this.id_public_user_info,
      userAmount:this.userAmountInfo?.mid_table_remark_008||0
    })
  }
  },

};
</script>

<style lang="scss" scoped>
@import "../../styles/variables";

.detail-title {
  border-bottom: 1px solid #e3e3e3;
  padding: 16px 0;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.detail-content {
  padding: 24px 24px 0;
  .el-row {
    margin-bottom: 36px;
    font-size: 14px;
    display: flex;

    .el-col {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      .left-text {
        color: #2d2f33;
      }
      .el-input {
        ::v-deep {
          .el-input__inner {
            border-radius: 0;
            border: none;
            border-bottom: 1px solid $tiffany;
            padding-left: 0;
            text-align: right;
          }
        }
      }
    }
  }
}

.other-content {
  .item-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border: 1px solid #e3e3e3;
    border-bottom: none;
    &:last-child {
      border-bottom: 1px solid #e3e3e3;
    }

    .number-text {
      color: #29AE6D;
      font-weight: bold;
      margin-top: 12px;
    }

    .el-button {
      background-color: transparent;
      border: none;
      color: #29AE6D;
    }
  }
}
</style>
